<?php
/*
CREATE TABLE `points` (
   `id` int(8) NOT NULL auto_increment,
   `timestamp` timestamp default now(),
   `lat` double(20,17) NOT NULL default '0.000000',
   `lon` double(20,17) NOT NULL default '0.000000',
   `altitude` double (8,4) NOT NULL default '0.000',
   `speed` double (8,4) NOT NULL default '0.000',
   PRIMARY KEY  (`id`)
);
*/
function receiveCoords($method_name, $params, $app_data) {
	$mysqli = mysqli_connect(
            'localhost',
            'gps',
            'gpsDB',
            'gps');

	$stmt = $mysqli->prepare("INSERT INTO points (track_id, time, latitude, longitude, course, speed, climb, altitude) VALUES ('1', ?, ?, ?, ?, ?, ?, ?)");
	$stmt->bind_param("ddddddd", $time, $latitude, $longitude, $course, $speed, $climb, $altitude);
	$time = $params[0];
	$latitude = $params[1];
	$longitude = $params[2];
	$course = $params[3];
	$speed = $params[4];
	$climb = $params[5];
	$altitude = $params[6];
	$stmt->execute();

	$stmt->close();
	$mysqli->close();

	return "Time:$time Latitude:$latitude Longitude:$longitude Course:$course Speed:$speed Climb:$climb Altitude:$altitude";
}

$xmlrpc_server = xmlrpc_server_create();
xmlrpc_server_register_method($xmlrpc_server, "maps.receiveCoords", "receiveCoords");
$request_xml = $HTTP_RAW_POST_DATA;
$response = xmlrpc_server_call_method($xmlrpc_server, $request_xml, '');
print $response;
xmlrpc_server_destroy($xmlrpc_server);
?>
